package logic

import (
	"context"
	"delivery/deliveryrpc/deliveryrpc"

	"delivery/api/internal/svc"
	"delivery/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterApiLogic {
	return &RegisterApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterApiLogic) RegisterApi(req *types.RegisterRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.DeliveryRpc.Register(l.ctx, &deliveryrpc.RegisterRequest{
		Account:     req.Account,
		Password:    req.Password,
		SenSmsCode:  req.SensmsCode,
		CaptchaCode: req.CaptchaCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "注册成功",
		Code:    200,
		Data:    sms,
	}, nil
	return
}
